﻿using System;
using System.Transactions;

namespace Nvigorate.Data
{
    public class TransactionManager : ITransactionManager, IDisposable
    {
        private TransactionScope _transactionScope;

        public void AbortTransaction()
        {
            if (_transactionScope != null)
            {
                _transactionScope.Dispose();
            }
        }

        public void BeginTransaction()
        {
            _transactionScope = new TransactionScope(TransactionScopeOption.Required);
        }

        public void CompleteTransaction()
        {
            _transactionScope.Complete();
            _transactionScope.Dispose();
        }

        public void Dispose()
        {
            if (_transactionScope != null) _transactionScope.Dispose();
        }
    }
}